package com.lening.controller;

import com.lening.entity.Player;
import com.lening.entity.School;
import com.lening.entity.Team;
import com.lening.service.PlayerService;
import com.lening.utils.ResultVo;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 作者：曹明达
 * 创建时间：2020/9/1,9:14
 */
@Controller
public class PlayerController {
    @Autowired
    private PlayerService playerService;

    @RequestMapping("findAll")
    @ResponseBody
    private List<Player> findAll(){
        List<Player> list = playerService.findAll();
        return list;
    }
    @ResponseBody
    @RequestMapping("getSchool")
    private List<School> getSchool(){
        List<School> list = playerService.findSchool();
        return list;
    }
    @ResponseBody
    @RequestMapping("getTeam")
    private List<Team> getTeam(){
        return playerService.getTeam();
    }
    @ResponseBody
    @RequestMapping("savePlayer")
    private ResultVo savePlayer(@RequestBody Player player){
        try {
            playerService.savePlayer(player);
            return new ResultVo(true,"编辑成功");
        }catch (Exception e){
            return new ResultVo(false,"编辑失败");
        }
    }
    @ResponseBody
    @RequestMapping("deletePlayer")
    public ResultVo deletePlayer(@RequestBody long[] ids){
        try {
            playerService.deletePlayer(ids);
            return new ResultVo(true, "删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultVo(false, "删除失败");
        }

    }
}
